<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE HTML>
<html>
<head>
    <base href="<%=basePath%>"/>
	<link rel="Bookmark" href="favicon.ico" >
	<link rel="Shortcut Icon" href="favicon.ico" />
	<link rel="stylesheet" type="text/css" href="assets/H-ui/static/h-ui/css/H-ui.min.css" />
	<%--引起冲突的样式--%>
	<%--<link rel="stylesheet" href="${pageContext.request.contextPath}/assets/css/table.css"/>--%>
	<link rel="stylesheet" type="text/css" href="assets/H-ui/lib/Hui-iconfont/1.0.8/iconfont.css" />
	<link rel="stylesheet" type="text/css" href="assets/H-ui/static/h-ui.admin/skin/default/skin.css" id="skin" />
	<link rel="stylesheet" type="text/css" href="assets/H-ui/static/h-ui.admin/css/style.css" />
	<link rel="stylesheet" href="assets/css/bootstrap.css"/>
	<!--_footer 作为公共模版分离出去-->
	<script src="assets/js/jquery.min.js"></script>
	<script src="assets/js/bootstrap.min.js"></script>
	<!--/_footer /作为公共模版分离出去-->

<!--/meta 作为公共模版分离出去-->

<title>系统管理 - 科室管理 </title>
</head>
<body>
<div class="container">
	<div class="col-lg-10 col-lg-offset-1">
	<div>
		<div class="panel-body">
		</div>
			<table class="table table-hover table-bordered<%--table table-border table-bordered table-hover table-bg--%>">

				<thead>
					<%--<tr>--%>
						<%--<th scope="col" colspan="6">科室管理</th>--%>
					<%--</tr>--%>
					<tr class="text-c">
						<input type="hidden" name="pageNum" value="1">
						<th width="40">ID</th>
						<th width="100">科室名</th>
						<th width="100">科室地址</th>
						<th width="70">操作</th>
					</tr>
				</thead>
				<tbody>
				<c:if test="${not empty deskList.list}">
				<c:forEach items="${deskList.list}" var="x" >
					<tr class="text-c">
						<td>${x.deskId}</td>
						<td>${x.deskName}</td>
						<td>${x.deskSite}</td>
						<td class="f-14">
							<a title="编辑"  onclick="updateRole(this)" class="btn-primary btn-sm" style="text-decoration:none">详情</a>
							<a title="删除" href="javascript:;" onclick="delRole(${x.deskId})" class="btn-danger btn-sm" style="text-decoration:none">删除</a></td>
					</tr>
				</c:forEach>
				</c:if>
				</tbody>
			</table>


			<a class="btn-primary btn-sm" data-toggle='modal' data-target='#addModal' style="z-index: 1">添加科室</a>
			<div id="page" style="float: right" align="center">
				当前第${deskList.pageNum}页, 总共${deskList.pages}页，每页${deskList.pageSize}行，总共${deskList.total}行。
				<a id="firstPage" class="btn-sm btn-primary" onclick="changeNum(${deskList.prePage})">上一页</a>
				<a id="lastPage" class="btn-sm btn-primary" onclick="changeNum(${deskList.nextPage})">下一页</a>
			</div>
	<%--增加的模态框--%>
	</div>
</div>
	<%--评语类表添加模态框部分--%>
	<div class="modal fade" id="addModal" style="z-index:99999" >
		<div class="modal-dialog" style="width: 600px;z-index: 99999">
			<div class="modal-content">
				<!-- 模态框头部 -->
				<div class="modal-header" style="text-align: center;z-index: 1">
					<label>科室增加</label>
					<%--<button type="button" class="close" data-dismiss="addModal">&times;</button>--%>
				</div>
				<div class="modal-body">
					<form action="desk/add.action" method="post" id="addForm">
						<input type="text" hidden value="${desk.deskId}" name="deskId">
						<br>
						科室名称：<br>
						<input type="text" class="input-text" value="" placeholder="" id="deskName" name="deskName" datatype="*4-16" >
						<span  id="deskName_input" style="font-size: 20px"></span>
						<br>
						科室地址：<br>
						<input type="text" class="input-text" value="" placeholder="" id="deskSite" name="deskSite" datatype="*4-16" >
						<span  id="deskSite_input" style="font-size: 20px"></span>
						<br>
						</form>
				</div>
				<div class="modal-footer">
					<a class="btn-primary btn-sm" onclick="addRole()">提交</a>
					<a class="btn-primary btn-sm" onclick="returnRoles()">返回</a>
				</div>
			</div>
		</div>
	</div>


	<%--修改--%>
	<div class="modal fade" id="updateModal1" style="z-index:99999" >
		<div class="modal-dialog" style="width: 600px;z-index: 99999">
			<div class="modal-content">
				<!-- 模态框头部 -->
				<div class="modal-header" style="text-align: center;z-index: 1">
					<label>科室修改</label>
					<%--<button type="button" class="close" data-dismiss="addModal">&times;</button>--%>
				</div>
				<div class="modal-body">
					<form action="desk/update.action" method="post" id="addForm1">
						<input type="text" hidden  name="deskId" id="deskId">
						<br>
						科室名称：<br>
						<input type="text" class="input-text" value="" placeholder="" id="deskName1" name="deskName" datatype="*4-16" >
						<span  id="deskName_input1" style="font-size: 20px"></span>
						<br>
						科室地址：<br>
						<input type="text" class="input-text" value="" placeholder="" id="deskSite1" name="deskSite" datatype="*4-16" >
						<span  id="deskSite_input1" style="font-size: 20px"></span>
						<br>
						<br>
					</form>
				</div>
				<div class="modal-footer">
					<a class="btn-sm btn-primary" onclick="updateRole1()">提交</a>
					<a class="btn-sm btn-primary" onclick="returnRoles()">返回</a>
				</div>
			</div>
		</div>
	</div>
<script type="text/javascript">
	function updateRole1(){
        var flag=true;
        var deskId=$("#deskId").val();
        var deskName=$("#deskName1").val();
        var deskSite=$("#deskSite1").val();
        var addForm1=$("#addForm1");
        var deskName_input1=$("#deskName_input1");
        var deskSite_input1=$("#deskSite_input1");
        deskName_input1.text("");
        deskSite_input1.text("");
        if(deskName==null||deskName=='') {
            deskName_input1.text("科室名不能为空");
            flag = false;
        }
        if(deskSite==null||deskSite=='') {
            deskSite_input1.text("科室地址不能为空");
            flag = false;
        }
        if(flag){
            $.post("desk/update.action",
                {"deskId":deskId,"deskName":deskName,"deskSite":deskSite},
                function (result) {
                    console.log(result);
                    console.log(typeof result);
                    if(result==true){
                        alert("修改成功")
                        window.location.href="desk/desk.action"
                    }else if(result==false){
                        alert("添加失败");
                    }
                })
        }
	}
	function returnRoles(){
        window.location.href="desk/desk.action"
	}
function updateRole(obj) {
    var tds= $(obj).parent().parent().find('td');
    $("#deskId").val(tds.eq(0).text());
    $("#deskName1").val(tds.eq(1).text());
    $("#deskSite1").val(tds.eq(2).text());
    $('#updateModal1').modal({show:true});
}
function addRole() {
    var flag=true;
    var deskId=$("#deskId").val();
    var deskName=$("#deskName").val();
    var deskSite=$("#deskSite").val();
    var addForm=$("#addForm");
    var deskName_input=$("#deskName_input");
    var deskSite_input=$("#deskSite_input");
    deskName_input.text("");
    deskSite_input.text("");
    if(deskName==null||deskName=='') {
        deskName_input.text("科室名不能为空");
        flag = false;
    }
    if(deskSite==null||deskSite=='') {
        deskSite_input.text("科室地址不能为空");
        flag = false;
    }
    if(flag){
        $.post("desk/add.action",
            {"deskId":deskId,"deskName":deskName,"deskSite":deskSite},
            function (result) {
                console.log(result);
                console.log(typeof result);
                if(result==true){
                    alert("添加成功")
                    window.location.href="desk/desk.action"
                }else if(result==false){
                    alert("添加失败");
                }
            })
    }
}
	function delRole(obj) {
        var deskId = obj;
        $.post("desk/del.action",
            {"deskId": deskId},
			function (date) {
				console.log(date);
				console.log(typeof date);
				if(date==true){
				    window.alert("删除科室成功");
					window.location.href="desk/desk.action"
				}else {
				    window.alert("科室中有工作人员，无法删除");
					window.location.href="desk/desk.action"
				}
            }
        )
    }
    function changeNum(obj) {
        var pageNum=obj;
        window.location.href="desk/desk.action?pageNum="+pageNum;
    }

</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>